package com.rongjih.learn.webflux.annotation;

import com.rongjih.learn.webflux.Student;
import com.rongjih.learn.webflux.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class StudentController {
  @Autowired
  private StudentService studentService;

  @RequestMapping(value = "/students1", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  public Flux<Student> findAll() {
    System.out.println("annotation: thread.id=" + Thread.currentThread().getId());
    return studentService.all();
  }
}